package com.xbongbong.crm.handle.explain.impl;

import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.parent.interfaces.explain.BusinessExplainHandle;
import com.xbongbong.pro.businessdata.pojo.dto.FormatExplainDTO;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.enums.OperatePageEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.QuotationEnum;
import com.xbongbong.saas.help.ExplainHelp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * @author 吴峰
 * @date 2022/01/18 17:16
 */
@Service("quotationExplainHandleImpl")
@Slf4j
public class QuotationExplainHandleImpl implements BusinessExplainHandle {

    @Resource
    private ExplainHelp explainHelp;

    @Override
    public List<Integer> businessType() {
        return Arrays.asList(XbbRefTypeEnum.QUOTATION.getCode());
    }

    @Override
    public List<FieldAttrEntity> newHandleExplain(FormatExplainDTO formatExplainDTO) throws XbbException {
        List<FieldAttrEntity> entities = formatExplainDTO.getExplainList();
        String corpid = formatExplainDTO.getCorpid();
        for (FieldAttrEntity fieldAttrEntity : entities) {
            String attr = fieldAttrEntity.getAttr();
            if (Objects.equals(attr, QuotationEnum.PRODUCT.getAttr())) {
                explainHelp.formatSelectProductExplains(fieldAttrEntity, XbbRefTypeEnum.QUOTATION, corpid, OperatePageEnum.NEW.getCode(), false);
                fieldAttrEntity.setSupportScanning(BasicConstant.ONE);
            } else if (Objects.equals(attr, QuotationEnum.PRODUCT_TOTAL.getAttr())) {
                fieldAttrEntity.setEditable(BasicConstant.ZERO);
            } else if (Objects.equals(attr, QuotationEnum.QUOTATION_NO.getAttr())) {
                fieldAttrEntity.setEditable(BasicConstant.ZERO);
            }
        }
        return entities;
    }
}
